package com.xaicode.auth.mapper;

import com.xaicode.auth.annotation.AuthDataScope;
import com.xaicode.auth.base.BaseMapper;
import com.xaicode.auth.constant.DatasourceName;
import com.xaicode.auth.entity.SysUser;
import com.xaicode.auth.entity.SysUserPost;
import com.xaicode.auth.entity.SysUserRole;
import com.xaicode.auth.security.domain.dto.AssignRoleDto;
import com.xaicode.auth.security.domain.params.SysRoleUserQueryParam;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
@DS(DatasourceName.CCM)
public interface SysUserMapper extends BaseMapper<SysUser> {

    List<SysUser> selectUserList2(@Param("mobile") String mobile,
                                  @Param("nickname") String nickname,
                                  @Param("username") String username,
                                  @Param("startDateTime") String startDateTime,
                                  @Param("endDateTime") String endDateTime,
                                  @Param("deptId") Integer deptId,
                                  @Param("lastSql") String lastSql);


    @Deprecated
    @AuthDataScope(userAlias = "u", deptAlias = "d", userField = "id")
    List<SysUser> selectUserList(@Param(Constants.WRAPPER) Wrapper<SysUser> wrapper);

    void insertBatchUserPost(List<SysUserPost> posts);

    void insertBatchUserRole(List<SysUserRole> roles);

    void deleteUserPostByUserId(@Param("userId") String id);

    void deleteUserRoleByUserId(@Param("userId") String id);

    void cancelAuth(AssignRoleDto dto);

    @AuthDataScope(userAlias = "u", deptAlias = "d", userField = "id")
    List<SysUser> selectRoleUserList(SysRoleUserQueryParam param);

    int selectCountByRoleIds(@Param("roleIds") List<Integer> roleId);

    int selectCountByPostIds(@Param("postIds") List<Integer> postId);
}
